//
//  PersonController.m
//  GuoBang
//
//  Created by 梧桐树 on 16/4/27.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "PersonController.h"
#import "GerenxinxiViewController.h"
#import "MoreViewController.h"
#import "YiJianViewController.h"
#import "SaiJinJuanViewController.h"
#import "MyBookingViewController.h"

@interface PersonController ()

@end

@implementation PersonController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNav];
    [self setData];
    [self setUI];
    
}
-(void)setNav{
    self.title=@"我";
    //设置返回按键
    //返回按键颜色
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    //返回按键图标
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
}
-(void)setUI{
    //hearderHi(详见h文件)
    hearderHi=15;
    //关闭滚动
    tab.scrollEnabled=NO;
    //隐藏分隔线
     tab.separatorStyle = UITableViewCellSeparatorStyleNone;
}
-(void)setData{
    //功能列表数据设置
    listArry1=@[@{@"icon":@"person_ico_message@2x.png",@"title":@"个人信息"},
                @{@"icon":@"person_ico_order@2x.png",@"title":@"我的订单"},
                @{@"icon":@"person_ico_quan@2x.png",@"title":@"我的代金券",@"text":@"我的代金券"}
                ];
    listArry2=@[@{@"icon":@"person_ico_friend@2x.png",@"title":@"邀请朋友",@"text":@"邀请得代金券"},
                @{@"icon":@"person_ico_return@2x.png",@"title":@"意见反馈"},
                @{@"icon":@"person_ico_more@2x.png",@"title":@"更多"}
                ];


}
#pragma mark TabView协议方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return listArry1.count;
            break;
        case 1:
            return listArry2.count;
            break;
            
        default:
            break;
    }
    return 0;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return hearderHi;
    
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, hearderHi)] ;
    
    [headerView setBackgroundColor:[SEATools stringToColor:@"efeff4"]];
    return headerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //根据CELL高度自动获取行高
    UITableViewCell *cell=[self tableView:tab cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    FunctionListCell*cell=[tab dequeueReusableCellWithIdentifier:@"FunctionListCell"];
   
    if(cell==nil)
    {
        NSArray *arr=[[NSBundle mainBundle]loadNibNamed:@"FunctionListCell" owner:nil options:nil];
        cell=[arr objectAtIndex:0];
    }
  
    switch (indexPath.section) {
        case 0:
            cell.icon.image=[UIImage imageNamed:[[listArry1 objectAtIndex:indexPath.row] objectForKey:@"icon"]];
            cell.title.text=[[listArry1 objectAtIndex:indexPath.row] objectForKey:@"title"];
            if ([[listArry1 objectAtIndex:indexPath.row] objectForKey:@"text"]) {
                cell.text.text=[[listArry1 objectAtIndex:indexPath.row] objectForKey:@"text"];
            }
            if (indexPath.row==listArry1.count-1) {
                cell.line.hidden=YES;
            }
            break;
        case 1:
            cell.icon.image=[UIImage imageNamed:[[listArry2 objectAtIndex:indexPath.row] objectForKey:@"icon"]];
            cell.title.text=[[listArry2 objectAtIndex:indexPath.row] objectForKey:@"title"];
            if ([[listArry2 objectAtIndex:indexPath.row] objectForKey:@"text"]) {
                cell.text.text=[[listArry2 objectAtIndex:indexPath.row] objectForKey:@"text"];
            }
            if (indexPath.row==listArry2.count-1) {
                cell.line.hidden=YES;
            }
            break;
            
        default:
            break;
    }
   
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
        
    
        
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //关闭选定高光效果
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    switch (indexPath.section) {
            //列表一点击
        case 0:
        {
            if (indexPath.row == 0) {
                GerenxinxiViewController *gerenVC = [GerenxinxiViewController new];
                [self.navigationController pushViewController:gerenVC animated:YES];
                
            }else if (indexPath.row == 1) {
                MyBookingViewController *myBookVC = [MyBookingViewController new];
                [self.navigationController pushViewController:myBookVC animated:YES];
                
            }else if (indexPath.row == 2) {
                SaiJinJuanViewController *jinVC = [SaiJinJuanViewController new];
                [self.navigationController pushViewController:jinVC animated:YES];
            }
        
        }
            break;
            //列表二点击
        case 1:
        {
        
            if (indexPath.row == 0) {
                
                FriendViewController *friVC = [FriendViewController new];
                [self.navigationController pushViewController:friVC animated:YES];
                
            }else if (indexPath.row == 1) {
                
                YiJianViewController *yijianVC = [YiJianViewController new];
                [self.navigationController pushViewController:yijianVC animated:YES];
                
                
            }else if (indexPath.row == 2) {
                MoreViewController *moreVC = [MoreViewController new];
                [self.navigationController pushViewController:moreVC animated:YES];
            }
            
            
            
            
            
        
        }
             break;
        default:
            break;
    }

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
